package com.baor.controller;


import com.baor.config.TokenService;
import com.baor.domain.MenuVO;
import com.baor.domain.UserVO;
import com.baor.service.MenuService;
import com.baor.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class MenuController {
    @Autowired
    private MenuService menuService;
    @Autowired
    private TokenService tokenService;


    @RequestMapping(value="/menuList")
    public R menuList(@RequestHeader("token") String token){
        // 1. 从请求头获取token并解析用户信息
        UserVO userInfo = tokenService.getUserInfo(token);
        // 2. 获取用户ID
        Integer userId = userInfo.getId();
        // 3. 传入用户ID查询菜单
        return this.menuService.menuList(userId);
    }

//点击添加返回上级菜单列表
@RequestMapping(value="/returnmenu")
public R returnmenu(){

    return this.menuService.returnmenu();
}
//添加菜单
    @RequestMapping(value="/insertMenu")
    public R menuList(@RequestBody MenuVO menuVO){
       return this.menuService.insertMenu(menuVO);
    }
//编辑菜单
    @RequestMapping(value="/updateMenu")
    public R updateMenu(@RequestBody MenuVO menuVO){
        return this.menuService.updateMenu(menuVO);
    }
}
